capture log close
clear
clear matrix
set mem 10000000
set more off
#delimit ;

*******************************************************************************************************;

*Ritter & Conrad APSR 2016;
*This .do file runs the models for the Africa test as reported in Table 1;

*******************************************************************************************************;

use RC_APSR_Data_RevisedNov23.dta, clear;
tsset adm0_adm1 date; 
sort cow year;
merge cow year using "Latent_Democracy.dta";
rename mean latent_democracy;
drop _merge; 
tsset adm0_adm1 date; 

*Generate variables;

tab etype1; 

gen dissentcount=etype1+etype2+etype3+etype4+etype5+etype6+etype8
	+escalation1+escalation2+escalation3+escalation4+escalation5+escalation6+escalation8; 
	
gen represscount=escalation7+repBINARYone+repBINARYtwo;

tab etype1;
	
drop etype1 etype2 etype3 etype4 etype5 etype6 etype7 etype8 etype9 etype10 
	escalation0 escalation1 escalation2 escalation3 escalation4 escalation5 escalation6 escalation7
	escalation8 escalation9 escalation10 etypeNEG9 repBINARYone repBINARYtwo repBINARYzero;
	
gen repressbinary=.;
replace repressbinary=1 if represscount>=1;
replace repressbinary=0 if represscount==0;

gen dissentbinary=.;
replace dissentbinary=1 if dissentcount>=1;
replace dissentbinary=0 if dissentcount==0;

gen lograin=ln(rainnonull_mean);
replace lograin=0 if lograin==.;

gen democracydissent=latent_democracy*dissentcount;
gen democracyrain=latent_democracy*lograin;
gen democracyfullrain=latent_democracy*rainnonull_mean;

gen raindeviations=rainnonull_mean-(annualrainsum/365);

xtset adm0_adm1 date;

*******************************************************************************************************;

*Non-instrumented regression;
reg represscount dissentcount urban_mean, robust;

*******************************************************************************************************;

*Instrumented regression;
ivreg2 represscount urban_mean (dissentcount = lograin rainannualpct), robust first;
ivreg2 represscount urban_mean (dissentcount = lograin rainannualpct) if latent_democracy<=0, robust first;
ivreg2 represscount urban_mean (dissentcount = lograin rainannualpct) if latent_democracy>0, robust first;

*******************************************************************************************************;
